import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import it.uniroma3.dia.digraph.algorithm.utility.Utility;
import it.uniroma3.dia.digraph.algorithm.utility.kouterplanar.outerplanar.OuterplanarGraph;
import it.uniroma3.dia.digraph.algorithm.utility.kouterplanar.outerplanar.OuterplanarNode;
import it.uniroma3.dia.digraph.io.util.IoManager;
import it.uniroma3.dia.digraph.view.Finestrella;
import it.uniroma3.dia.digraph.view.View;

import org.graphdrawing.graphml.xmlns.GraphType;
import org.graphdrawing.graphml.xmlns.NodeType;

/**
 * 
 */

/**
 * @author Cionzo
 *
 */
public class OuterplanarTester {
    
    public static void main(String[] args) throws IOException {
	GraphType g = new IoManager().loadFromFile("xml\\kouterplanar\\kouterpl\\2outerplanar.xml").getGraph();
	OuterplanarGraph og = new OuterplanarGraph(g);
	View v = new View(g);
	v.pack();
	v.setVisible(true);
	v.update(g);
	v.repaint();
	
	System.out.println("bla");
	Finestrella.getChar();
	Map<Integer,  List<OuterplanarNode>> layers = Utility.decomposeToOuterplanarLayers(g);
	List<OuterplanarNode> layer, boundary;
	boundary = layers.get(0);
	OuterplanarNode h = null;
	for (Integer i : layers.keySet()) {
	    
	    
	   
		layer = layers.get(i);

		for (OuterplanarNode on : layer) {
		    on.setParent2Lambda(Utility.homogeneusCoords(on, boundary));
		    if (on.getId().equals("h"))
			h = on;
		}
	
	}
	for (List<OuterplanarNode> l : layers.values())
	    if (l.equals(layers.get(0))) {
		for (OuterplanarNode on : l)
			on.setParent2Lambda(null);
	    }
	    else {
		for (OuterplanarNode on : l)
			on.updateCoords();
	    }
	
	
	
	v.update(g);
	v.repaint();
	System.out.println("beh");
	Finestrella.getChar();
	h.getNode().setY(h.getNode().getY()*2);
	h.getNode().setX(h.getNode().getX()/2);
	
	for (List<OuterplanarNode> l : layers.values())
	    if (l.equals(layers.get(0))) {
		for (OuterplanarNode on : l)
			on.setParent2Lambda(null);
	    }
	    else {
		for (OuterplanarNode on : l)
			on.updateCoords();
	    }
	
	
	v.update(g);
	v.repaint();
	System.out.println("buh");
	Finestrella.getChar();
	System.exit(0);
	
	
	
	
	
    }
    
    public static void dmain(String[] args) {
	double d = Utility.det(12, 78, 45, 2, 76, 496, 678, 296, 7);
	System.out.println(d);
    }

}
